import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
  state: () => ({
    loading: false,
    theme: 'light',
    size: 'default' as 'default' | 'large' | 'small'
  }),
  actions: {
    setLoading(loading: boolean) {
      this.loading = loading
    },
    initTheme() {
      const savedTheme = localStorage.getItem('theme') || 'light'
      this.setTheme(savedTheme)
    },
    setTheme(theme: string) {
      this.theme = theme
      document.documentElement.setAttribute('data-theme', theme)
      localStorage.setItem('theme', theme)
    },
    toggleTheme() {
      this.setTheme(this.theme === 'light' ? 'dark' : 'light')
    }
  }
})